class Food {
  constructor(el) {
    this.el = el
    this.box = 20
    this.foodObj = null
    this.foodX = 0
    this.foodY = 0
  }
  create() {
    //创建div
    let divObj = document.createElement('div')
    divObj.style.width = this.box + 'px'
    divObj.style.height = this.box + 'px'
    divObj.style.background = 'pink'
    divObj.style.position = 'absolute'
    this.el.appendChild(divObj)
    this.foodObj = divObj
    this.move()
  }
  move() {
    let foodXMaxNum = this.el.clientWidth / this.box -1
    let foodYMaxNum = this.el.clientHeight / this.box -1
    //console.log(foodXMaxNum);
    //console.log(foodYMaxNum);
    this.foodX = Math.floor(Math.random() * (foodXMaxNum+1))
    this.foodY = Math.floor(Math.random() * (foodYMaxNum+1))
    //console.log(this.foodX, this.foodY);
    this.foodObj.style.left = (this.foodX * this.box) + 'px'
    this.foodObj.style.top = (this.foodY * this.box) + 'px'
  }
}